package com.seecen.controller;

import com.seecen.common.BaseResponse;
import com.seecen.pojo.entity.Region;
import com.seecen.service.RegionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/region")
@CrossOrigin
public class RegionController {

    @Autowired
    private RegionService regionService;

    @GetMapping("/province")
    public BaseResponse<List<Region>> getProvinceList() {
        return regionService.getProvinceList();
    }

    @GetMapping("/child")
    public BaseResponse<List<Region>> getChildRegions(@RequestParam Long parentId) {
        return regionService.getChildRegions(parentId);
    }

    // 新增：查询指定地区的最快上门时间
    @GetMapping("/fastest")
    public BaseResponse<Integer> getFastestArrivalTime(@RequestParam Long regionId) {
        return regionService.getFastestArrivalTime(regionId);
    }

    // 新增：查询父地区下属的最快上门时间（如省份下最快的城市）
    @GetMapping("/parent/fastest")
    public BaseResponse<Integer> getMinArrivalTimeByParentId(@RequestParam Long parentId) {
        return regionService.getMinArrivalTimeByParentId(parentId);
    }
}